#pragma once
#include "Box2DManager.h"

class Sprite;
struct PartCreateInfo
{
	float2		local_position;
	float		local_rotation;
	int			part_type;
	float2		size;
	std::string texture;
	bool		reverse;
	float		density;
	float2		core_position;
	uint		uid;

	PartCreateInfo()
	{
		local_rotation = 0.f;
		part_type = 0;
		reverse = false;
		density = 1.0f;
	}
};

struct JointCreateInfo
{
	uint partA_uid;
	uint partB_uid;

	JointCreateInfo()
	{
		partA_uid = 0;
		partB_uid = 0;
	}
};

class RobotPartBase
{
public:
	// constructor.
	RobotPartBase();
	
	// destructor.
	virtual ~RobotPartBase(){};

	// update
	virtual void OnUpdate(float frameTime) = 0;

	// render
	virtual void OnPreRender() = 0;

	virtual void Initialize() = 0;
	
	virtual float2 GetPosition() = 0;

	virtual void Create(PartCreateInfo info){};

	void OnUpdateAction(float frameTime);

	virtual void SetOwnerId(uint id);

	virtual void UpdateCommand(RobotCommandState c);

	virtual	void SetTransform(const float2& position, float angle);

	virtual void SetTransform(const b2Transform& transform);

	virtual void Reset();

	void SetActive(bool flag);

	void SetPartType(PartType type);

	PartType GetPartType();

	const b2BodySmart& GetBodySmart();
protected:
	virtual void OnActionIdle(float frameTime){};

	virtual void OnActionMoveForward(float frameTime){};

	virtual void OnActionMoveBack(float frameTime){};

	b2BodySmart		 m_b2BodyPart;

	PartType		 m_partType;
	PartAction		 m_partAction;

	PartCreateInfo	 m_create_info;
public:
	uint			 uid;
	uint			 owner_id;
};

class RobotPartBody : public RobotPartBase
{
public:
	RobotPartBody();
	
	~RobotPartBody();

	// update
	void OnUpdate(float frameTime);

	// render
	void OnPreRender();

	void Initialize();

	void Create(PartCreateInfo info);

	void SetTransform(float2 position, float angle);

	float2 GetPosition();

	float GetRotation();
private:
	void CreateBox2D();
	
	std::shared_ptr<Sprite> m_PartSprite;

	float2 m_Poistion;

	float m_Rotation;

	
};